#ifndef _Persistent_h_
#define _Persistent_h_

#include "Factory/Factory.h"
#include <string>

using namespace common;

namespace persist
{
//the mechanism that can make objects of a class persistent (e.g. on disk) is
class Persistor;

//Persistor operates with objects that are 
class Persistent : public common::Identifiable
{
//handled by this persistor
	Persistor* persistor;
//my name
	std::string name;
public:
//constructors
	Persistent(){persistor=0;}
	Persistent(const std::string& _name){name=name;persistor=0;}
	Persistent(Persistor* _persistor){persistor=_persistor;}
	Persistent(Persistor* _persistor, const std::string& _name){persistor=_persistor;name=_name;}
//set/get persistor	
	void setPersistor(Persistor* _persistor){persistor=_persistor;}
	Persistor* getPersistor(){return persistor;}
//set/get name
	void setName(const std::string& _name){name=_name;}
	const std::string& getName(){return name;}
//read/write
	virtual void load(); //get ready and call persistor->load(this)
	virtual void save(); //get ready and call persistor->save(this)
};


//an object stored on disk is preceeded by a description as
//to how it should be handled. This description exists as
struct Record
{
								//an object on disk is uniquely identified by:
	Identifier id;				//class name (guid anyone??)
	std::string persistorName;	//name of the persistor that can handle it
	std::string persistentName; //own name

	Record() {}
	Record(const Identifier& _id,
		const std::string& _persistorName,
		const std::string& _persistentName)
		: id(_id),persistorName(_persistorName),
		persistentName(_persistentName) {}
//less.
	bool operator<(const Record& record) const
	{
		if (id < record.id) return true;
		else if (record.id < id) return false;
		else if (persistorName < record.persistorName) return true;
		else if (record.persistorName < persistorName) return false;
		else if (persistentName < record.persistentName) return true;
		return false;
	}
		
};

} //namespace


#endif